package org.aceor.mddal.gateway.merger.function;

import org.aceor.mddal.gateway.merger.common.AbstractMergerInvokeHandler;
import org.aceor.mddal.gateway.merger.common.ResultSetQueryIndex;
import org.aceor.mddal.gateway.resultset.AggregateResultSet;
import org.aceor.mddal.gateway.util.ResultSetUtil;

import java.lang.reflect.Method;
import java.sql.SQLException;

/**
 * Created by lxue on 16/4/17.
 */
public class AggregateInvokeHandler extends AbstractMergerInvokeHandler<AggregateResultSet> {
    public AggregateInvokeHandler(AggregateResultSet resultSet) {
        super(resultSet);
    }

    @Override
    protected Object doMerge(AggregateResultSet resultSet, Method method, ResultSetQueryIndex resultSetQueryIndex) throws ReflectiveOperationException, SQLException {
        return ResultSetUtil.convertValue(
                resultSet.getCurrentAggregateResultSet().getValue(resultSetQueryIndex), method.getReturnType());
    }
}
